$(document).ready(function() {
    $("form.formstylevalidate").submit(function(e){
        if($(this).valid()) {
            return true;
        } else {
            e.preventDefault();
            return false;
        }        
    });
    
    $("a.confirm").click(function(e){
        var c = confirm($(this).attr("confirm"));
        if(!c){
            e.preventDefault();
        }        
    });
    
});

var systemapp = {
    addPageTab: function()
    {
        FB.ui(
        {
            method: 'pagetab',
            redirect_uri: 'http://ssl.socialmediatoolbox.no/likewinn/users/www/admin/?action=apppublish'
        },
        function(response) {
            if (response != null && response.tabs_added != null) {
                $.each(response.tabs_added, function(pageid) {
                    FB.api(pageid, function(response) {
                        alert('redirect to ' + response.link);
                    });
                });

            }
        }
      );
    },
    deletePictureFile: function(setting, key){                
        systemapp.blockUIMessageBox("...");
        $.post("?action=deleteimg", {settingkey: setting, imgkey: key}, function(r){     
            $("#" + key).parent().parent().parent().find("div img").fadeOut();
            $("#" + key).parent().parent().parent().find("div a").fadeOut();    
            $.unblockUI();
        });        
    },
    blockUIMessageBox: function(message) {
        jQuery.blockUI({message: message,
            css: {
            border: 'none',
            padding: '15px',
            backgroundColor: '#000',
            '-webkit-border-radius': '10px',
            '-moz-border-radius': '10px',
            opacity: .5,
            color: '#fff'
        }});
        jQuery('.blockOverlay').attr('title','Click to unblock').click(jQuery.unblockUI);
    }
};
